package com.ham.mud.commands.spells.heal;

import com.ham.mud.ServerConnection;
import com.ham.mud.TargetableService;
import com.ham.mud.characters.player.Player;
import com.ham.mud.commands.spells.Spell;
import com.ham.mud.rooms.Room;
import com.ham.mud.rooms.RoomService;

/**
 * Created by hlucas on Jul 6, 2011 at 10:51:39 AM
 */
public class RefreshSpell extends Spell {
    @Override
    public int getManaCost() {
        return 5;
    }

    @Override
    public void castSpell(ServerConnection connection, String target) {
        Player player = connection.getPlayer();
        int mana = player.getVitals().getMana();
        if(mana < 5) {
            connection.printSolo("You do not have enough mana to cast that spell.");
            return;
        }

        Room room = RoomService.getRoom(player.getZone(), player.getAtX(), player.getAtY());
        if(target == null || target.equals("")) {
            player.getVitals().decrementMana(5);
            player.getVitals().incrementMove(50);
            connection.printSolo("You speak a few words into the wind and you feel refreshed.");
        } else {
            Player targetPlayer = (Player) TargetableService.findTarget(target, room.getOtherPlayers(connection));
            if(targetPlayer == null) {
                connection.printSolo("You do not see that person here.");
                return;
            }
            player.getVitals().decrementMana(5);
            targetPlayer.getVitals().incrementMove(50);
            connection.printSolo("You speak a few words into the wind and " + targetPlayer.getName() + " looks refreshed.");
            room.printToOthers(player.getName() + " casts a refresh spell.", connection);
        }
    }

    @Override
    public String getName() {
        return "Refresh";
    }
}
